<?php 
$Items = $this->Items;
?>
<script type="text/javascript">
	function loadPage(x,url){
		var div_name = 'div#status' + x;
		//$(div_name).html('');
		$(div_name).load(url);
	}
</script>
<div class="content-box bt-space20">
<div class="content-box">
	<div class="box-body">
		<div class="box-wrap clear">
		
			<!-- BASIC STYLE TABLE OPENABLE -->
			<h2>News</h2>
			
			<table class="basic" cellspacing="0">
			<caption>List of News
					<span style="float: right;">
							<?php $lnkAdd = $this->url(array('module'=>'admin','controller'=>'news','action'=>'add'));?>
							<button class="button red small" type="button" onclick="toSite('<?php echo $lnkAdd;?>')">Add</button>
						</span>
			</caption>
			<thead>
			<tr>			
				<th width="5%">&nbsp;</th>
				<th width="75%">Title</th>
				<th width="10%">Status</th>
				<th width="10%">Action</th>
			</tr>
			</thead>
			<tbody>
			<?php foreach($Items as $new){
						$linkEdit = $this->url(array('module'=>'admin','controller'=>'news','action'=>'edit','id'=>$new['id']),null,true);
						$linkDelete = $this->url(array('module'=>'admin','controller'=>'news','action'=>'delete','id'=>$new['id']),null,true);
			?>
			<tr class="box-slide-head">			
				<td class="vcenter slide-but"><span>more</span></td>
				<td class="vcenter title"><?php echo $new['title'];?></td>
				<td class="vcenter">
					<div id="status-div-<?php echo $new['id'];?>" style="padding-left:8px;">					
						<input type="hidden" id="status" value="<?php echo $new['status'];?>" />
						<?php if ($new['status'] == 1) {?>
						<img src="public/images/ball_green_16.png" class="block clickable" alt="" onclick="javascript:changeStatus(<?php echo $new['status'];?>,<?php echo $new['id'];?>);"/>
						<?php } else { ?>
						<img src="public/images/ball_red_16.png" class="block clickable" alt="" onclick="javascript:changeStatus(<?php echo $new['status'];?>,<?php echo $new['id'];?>);"/>
						<?php } ?>
					</div>
				</td>
				<td class="vcenter">
					<img src="public/images/ico_eye_16.png" class="fl-space" alt="" />
					<a href="<?php echo $linkEdit;?>"><img src="public/images/ico_edit_16.png" class="fl-space clickable" alt="Edit" /></a>
					<a href="<?php echo $linkDelete;?>" onclick="javascript:confirm('Bạn có chắc chắc muốn xóa bài : <?php echo $new['title'];?>');"><img src="public/images/ico_delete_16.png" class="fl clickable" alt="Delete" /></a>
				</td>
			</tr>
			<tr>
				<td class="box-slide-body hidden" colspan="7">
					<p class="clean-padding bt-space5">
						<small style="padding-left: 70px;"><?php echo $new['lead']?></small>
					</p>
				</td>
			</tr>
			<?php } ?>
			</tbody>
			</table>
			
		</div> <!-- end of box-wrap -->
	</div> <!-- end of box-body -->
	</div> <!-- end of content-box -->
<script type="text/javascript">
		function changeStatus(status,id){
			if(status == 1) status = 0;
			else status = 1;
			$.ajax({
				type:"POST", //Phương thức gửi request là POST hoặc GET
			  	data:"status="+ status + "&id=" + id, //tham số gửi kèm
			  	url:"<?php echo APPLICATION_URL;?>/admin/news/status/", //Đường dẫn tới nơi xử lý request ajax
			  	success: function (html){ //hàm gọi về khi thực hiện thành công
			  		$('#status-div-'+id).html(html);
				}
			});
	  		return false;		
		}
</script>